package com.zczc.web.controller;

import com.yishuifengxiao.common.tool.response.Response;
import com.zczc.service.MessageUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 15:31 2018-12-13
 * @Modify by:
 */
@RestController
@Api(tags = "向用户发送消息接口")
@RequestMapping("/zczc/messageUser")
@Validated
public class MessageUserController {

  private final static Logger log= LoggerFactory.getLogger(MessageUserController.class);

  @Autowired
  private MessageUserService messageUserService;

  @PostMapping("/sendMessageToUser")
  @ApiOperation(value = "批量向用户推送消息")
  public Response sendMessageToUser(@ApiParam(required = true,name = "userIds",value = "用户id值") @RequestBody(required = true) @NotEmpty(message = "userIds不能为空") @NotNull(message = "userIds不能为null") List<String> userIds,
     @ApiParam(required = true,name = "messageIds",value = "消息id值") @RequestBody(required = true) @NotNull(message = "messageIds不能为null") @NotEmpty(message = "messageIds不能为空") List<String> messageIds){
    try {
      messageUserService.addMessageUser(userIds,messageIds);
     return Response.suc();
    } catch (Exception e) {
      log.info("发送消息报错=================》"+e.getMessage());
      return Response.error(e.getMessage());
    }
  }

  @ApiOperation(value = "批量删除向用户发送的消息")
  @DeleteMapping("/deleteMessageToUser")
  public Response deleteMessageToUser(@ApiParam(required = true,name = "messageIds",value = "消息id值") @RequestBody(required = true) @NotNull(message = "messageIds不能为null") @NotEmpty(message = "messageIds不能为空")List<String> messageIds){
    messageUserService.deleteMessageByMessageIdLogic(messageIds);
    return Response.suc();
  }



}
